package com.space.rabbitmq.receiver;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


/**
 * 消息消费者6，配置了死信队列，如果该队列处理消息出现异常执行basicReject拒绝方法，就会将此队列消息删除移动到指定的死信队列
 *
 * @author zhanglei
 */
@Component
public class SixthConsumer {

    /**
     * queues  指定从哪个队列（queue）订阅消息
     * @param message
     */
    @RabbitListener(queues = {"sixth-queue"})
    public void handleMessage(String msg, Channel channel, Message message) throws IOException {
        // 处理消息
        System.out.println("SixthConsumer --- handleMessage：" + message);
        channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
    }
}
